import express from 'express';
import { Request, Response } from "express";
import { AppDataSource } from "../config/database";
import { success, failure } from '../utils/responses';
import { Category } from "../entities/Category";

const router = express.Router()

/**
 * 查询分类列表
 */
router.get('/', async function (_req:Request, res:Response) {
  try {
    const categoryRepository = AppDataSource.getRepository(Category)
    const categoryList = await categoryRepository.find()
    console.log(categoryList)
    success(res, '查询分类成功', categoryList)
  } catch (error) {
    failure(res, error)
  }
});

export default router
